#!/bin/bash

virsh list
echo ""

running_vms=`virsh list |tail -2 |awk '{print $2}'`
nums=`echo $running_vms|grep -v ^$|wc -l`

if [ $nums -eq 0 ]; then
echo "No Guest OS running."
exit 0
fi

for vm in `echo $running_vms`
do
echo "Now shutdown $vm ......"
virsh shutdown $vm
done
